package com.cch.cooperation.api.zone.schedule;

import com.cch.cooperation.api.common.properties.AppProperties;
import com.cch.cooperation.api.zone.service.ZoneRemindServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class ZoneRemindSchedule {

    @Resource
    private ZoneRemindServiceImpl zoneRemindService;
    @Resource
    private AppProperties appProperties;

    @Scheduled(cron = "0 */1 * * * ?")
    public void pushRemindToClient() {
        try {
            if (!appProperties.getPushEnable()) {
                return;
            }
            zoneRemindService.pushToClient();
        } catch (Exception e) {
            log.error("推送提醒任务异常", e);
        }
    }

    @Scheduled(cron = "0 1 0-2 * * ?")
    public void generateNotFreeRemind() {
        try {
            if (!appProperties.getPushEnable()) {
                return;
            }
            zoneRemindService.generateNotFreeRemind();
        } catch (Exception e) {
            log.error("生成次日提醒异常", e);
        }
    }

}
